package com.daryl.jcu_project1_creditscoreform;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class Loan_application8 extends Activity {

	/**
	 * @uml.property  name="nextPageBtn"
	 * @uml.associationEnd  
	 */
	private Button nextPageBtn;
	/**
	 * @uml.property  name="previousPageBtn"
	 * @uml.associationEnd  
	 */
	private Button previousPageBtn;
	/**
	 * @uml.property  name="addSecurityProperty"
	 * @uml.associationEnd  
	 */
	private Button addSecurityProperty;
	/**
	 * @uml.property  name="rmvSecurityProperty"
	 * @uml.associationEnd  
	 */
	private Button rmvSecurityProperty;
	/**
	 * @uml.property  name="securityProperty"
	 */
	private int securityProperty = 1;
	/**
	 * @uml.property  name="lA8SecurityProperty2"
	 * @uml.associationEnd  
	 */
	private LinearLayout LA8SecurityProperty2;
	/**
	 * @uml.property  name="propertyFlatUnitP1"
	 * @uml.associationEnd  
	 */
	private LinearLayout PropertyFlatUnitP1;
	/**
	 * @uml.property  name="propertyFlatUnitP2"
	 * @uml.associationEnd  
	 */
	private LinearLayout PropertyFlatUnitP2;
	/**
	 * @uml.property  name="propertyStudioP1"
	 * @uml.associationEnd  
	 */
	private LinearLayout PropertyStudioP1;
	/**
	 * @uml.property  name="propertyStudioP2"
	 * @uml.associationEnd  
	 */
	private LinearLayout PropertyStudioP2;
	/**
	 * @uml.property  name="radioDepositeUnderLienNo"
	 * @uml.associationEnd  
	 */
	private RadioButton radioDepositeUnderLienNo;
	/**
	 * @uml.property  name="radioDepositeUnderLienYes"
	 * @uml.associationEnd  
	 */
	private RadioButton radioDepositeUnderLienYes;
	/**
	 * @uml.property  name="flatUnitP1"
	 * @uml.associationEnd  
	 */
	private RadioButton FlatUnitP1;
	/**
	 * @uml.property  name="flatUnitP2"
	 * @uml.associationEnd  
	 */
	private RadioButton FlatUnitP2;
	/**
	 * @uml.property  name="studioP1"
	 * @uml.associationEnd  
	 */
	private RadioButton StudioP1;
	/**
	 * @uml.property  name="studioP2"
	 * @uml.associationEnd  
	 */
	private RadioButton StudioP2;
	/**
	 * @uml.property  name="houseP1"
	 * @uml.associationEnd  
	 */
	private RadioButton HouseP1;
	/**
	 * @uml.property  name="houseP2"
	 * @uml.associationEnd  
	 */
	private RadioButton HouseP2;
	/**
	 * @uml.property  name="companyUnitP1"
	 * @uml.associationEnd  
	 */
	private RadioButton CompanyUnitP1;
	/**
	 * @uml.property  name="companyUnitP2"
	 * @uml.associationEnd  
	 */
	private RadioButton CompanyUnitP2;
	/**
	 * @uml.property  name="landP1"
	 * @uml.associationEnd  
	 */
	private RadioButton LandP1;
	/**
	 * @uml.property  name="landP2"
	 * @uml.associationEnd  
	 */
	private RadioButton LandP2;
	/**
	 * @uml.property  name="duplexP1"
	 * @uml.associationEnd  
	 */
	private RadioButton DuplexP1;
	/**
	 * @uml.property  name="duplexP2"
	 * @uml.associationEnd  
	 */
	private RadioButton DuplexP2;
	/**
	 * @uml.property  name="townHouseP1"
	 * @uml.associationEnd  
	 */
	private RadioButton TownHouseP1;
	/**
	 * @uml.property  name="townHouseP2"
	 * @uml.associationEnd  
	 */
	private RadioButton TownHouseP2;
	
	//private RadioGroup rg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.loan_application8);
		nextPageBtn = (Button) findViewById(R.id.nextPageBtn);
		nextPageBtn.setOnClickListener(nextPage());
		previousPageBtn = (Button) findViewById(R.id.backPageBtn);
		previousPageBtn.setOnClickListener(previousPage());
		HouseP1 =(RadioButton) findViewById(R.id.radioPropertyType1P1);
		CompanyUnitP1 =(RadioButton) findViewById(R.id.radioPropertyType3P1);
		LandP1 =(RadioButton) findViewById(R.id.radioPropertyType4P1);
		DuplexP1 =(RadioButton) findViewById(R.id.radioPropertyType5P1);
		TownHouseP1 =(RadioButton) findViewById(R.id.radioPropertyType7P1);
		HouseP2 =(RadioButton) findViewById(R.id.radioPropertyType1P2);
		CompanyUnitP2 =(RadioButton) findViewById(R.id.radioPropertyType3P2);
		LandP2 =(RadioButton) findViewById(R.id.radioPropertyType4P2);
		DuplexP2 =(RadioButton) findViewById(R.id.radioPropertyType5P2);
		TownHouseP2 =(RadioButton) findViewById(R.id.radioPropertyType7P2);
		FlatUnitP1 =(RadioButton) findViewById(R.id.radioPropertyType2P1);
		FlatUnitP2 =(RadioButton) findViewById(R.id.radioPropertyType2P2);
		StudioP1 =(RadioButton) findViewById(R.id.radioPropertyType6P1);
		StudioP2 =(RadioButton) findViewById(R.id.radioPropertyType6P2);
		radioDepositeUnderLienNo = (RadioButton)findViewById(R.id.radioDepositeUnderLienNo);
		radioDepositeUnderLienYes = (RadioButton) findViewById(R.id.radioDepositeUnderLienYes);
		LA8SecurityProperty2 = (LinearLayout) findViewById(R.id.LA8SecurityProperty2);
		addSecurityProperty = (Button) findViewById(R.id.addSecurityPropertyBtn);
		addSecurityProperty.setOnClickListener(addSecurityProperty());
		rmvSecurityProperty = (Button) findViewById(R.id.rmvSecurityPropertyBtn);
		rmvSecurityProperty.setOnClickListener(rmvSecurityProperty());
		PropertyFlatUnitP1 = (LinearLayout) findViewById(R.id.LA8TypeOfPropertyFlatsUnitP1);
		PropertyFlatUnitP2 = (LinearLayout) findViewById(R.id.LA8TypeOfPropertyFlatsUnitP2);
		PropertyStudioP1= (LinearLayout) findViewById(R.id.LA8TypeOfPropertyStudioP1);
		PropertyStudioP2= (LinearLayout) findViewById(R.id.LA8TypeOfPropertyStudioP2);
		//rg = (RadioGroup) findViewById(R.id.radioGpDepositeUnderLien);
		radioDepositeUnderLienNo.setOnClickListener(radioDepositeCheck);
		radioDepositeUnderLienYes.setOnClickListener(radioDepositeCheck);
		HouseP1.setOnClickListener(radioPropertyCheckP1);
		CompanyUnitP1.setOnClickListener(radioPropertyCheckP1);
		LandP1.setOnClickListener(radioPropertyCheckP1);
		DuplexP1.setOnClickListener(radioPropertyCheckP1);
		TownHouseP1.setOnClickListener(radioPropertyCheckP1);
		FlatUnitP1.setOnClickListener(radioPropertyCheckP1);
		StudioP1.setOnClickListener(radioPropertyCheckP1);
		HouseP2.setOnClickListener(radioPropertyCheckP2);
		CompanyUnitP2.setOnClickListener(radioPropertyCheckP2);
		LandP2.setOnClickListener(radioPropertyCheckP2);
		DuplexP2.setOnClickListener(radioPropertyCheckP2);
		TownHouseP2.setOnClickListener(radioPropertyCheckP2);
		FlatUnitP2.setOnClickListener(radioPropertyCheckP2);
		StudioP2.setOnClickListener(radioPropertyCheckP2);

	}
	
/**
 * @uml.property  name="radioPropertyCheckP2"
 * @uml.associationEnd  multiplicity="(1 1)"
 */
public OnClickListener radioPropertyCheckP2 = new OnClickListener(){
		
		public void onClick(View ard0){
			if(FlatUnitP2.isChecked() ){
				PropertyFlatUnitP2.setVisibility(View.VISIBLE);
				PropertyStudioP2.setVisibility(View.GONE);
				
			}
			if(StudioP2.isChecked()){
				PropertyStudioP2.setVisibility(View.VISIBLE);
				PropertyFlatUnitP2.setVisibility(View.GONE);
				
			}
			if(HouseP2.isChecked() || CompanyUnitP2.isChecked() || LandP2.isChecked()
					|| DuplexP2.isChecked() || TownHouseP2.isChecked()){
				PropertyStudioP2.setVisibility(View.GONE);
				PropertyFlatUnitP2.setVisibility(View.GONE);
			}
			
		}
	};
	
/**
 * @uml.property  name="radioPropertyCheckP1"
 * @uml.associationEnd  multiplicity="(1 1)"
 */
public OnClickListener radioPropertyCheckP1 = new OnClickListener(){
		
		public void onClick(View ard0){
			if(FlatUnitP1.isChecked()){
				PropertyFlatUnitP1.setVisibility(View.VISIBLE);
				PropertyStudioP1.setVisibility(View.GONE);
				System.out.println("Checked Checke3");
			}
			if(StudioP1.isChecked()){
				PropertyStudioP1.setVisibility(View.VISIBLE);
				PropertyFlatUnitP1.setVisibility(View.GONE);
				System.out.println("Checked Checked2");
			}
			if(HouseP1.isChecked()|| CompanyUnitP1.isChecked() || LandP1.isChecked()
					|| DuplexP1.isChecked() || TownHouseP1.isChecked() ){
				System.out.println("Checked Checked");
				PropertyStudioP1.setVisibility(View.GONE);
				PropertyFlatUnitP1.setVisibility(View.GONE);
			}
		}
	};
	
	/**
	 * @uml.property  name="radioDepositeCheck"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	public OnClickListener radioDepositeCheck = new OnClickListener(){
		
		public void onClick(View ard0){
			if(radioDepositeUnderLienNo.isChecked()){
				LA8SecurityProperty2.setVisibility(View.GONE);
			}
			if(radioDepositeUnderLienYes.isChecked()){
				LA8SecurityProperty2.setVisibility(View.VISIBLE);
			}
		}
	};
	
	public void onRadioButtonClicked(View v) {
		boolean checked = ((RadioButton) v).isChecked();

		switch (v.getId()) {
		case R.id.radioDepositeUnderLienYes:
			if (checked) {
				LA8SecurityProperty2.setVisibility(View.VISIBLE);
			}
			break;
		case R.id.radioDepositeUnderLienNo:
			if (checked) {
				LA8SecurityProperty2.setVisibility(View.GONE);
			}
			break;
		}
	}

	private OnClickListener addSecurityProperty() {
		return new OnClickListener() {
			public void onClick(View v) {

				if (securityProperty == 1) {
					LA8SecurityProperty2.setVisibility(View.VISIBLE);
					rmvSecurityProperty.setVisibility(View.VISIBLE);
					addSecurityProperty.setVisibility(View.INVISIBLE);
				}

				securityProperty++;
			}

		};
	}

	private OnClickListener rmvSecurityProperty() {
		return new OnClickListener() {
			public void onClick(View v) {

				if (securityProperty == 2) {
					LA8SecurityProperty2.setVisibility(View.GONE);
					rmvSecurityProperty.setVisibility(View.INVISIBLE);
					addSecurityProperty.setVisibility(View.VISIBLE);
				}
				securityProperty--;
			}

		};
	}

	private OnClickListener nextPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(context, Loan_application9.class);
				startActivity(intent);

			}

		};
	}

	private OnClickListener previousPage() {
		final Context context = this;
		return new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(context, Loan_application7.class);
				startActivity(intent);
			}

		};
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_loan_application8, menu);
		return true;
	}

}
